package com.lty.jeeg.server.modules.fas.controller;

import com.lty.jeeg.server.common.dto.ResponseInfo;
import com.lty.jeeg.server.common.utils.BeanConverter;
import com.lty.jeeg.server.common.utils.ResponseUtil;
import com.lty.jeeg.server.modules.fas.dto.GoodsDTO;
import com.lty.jeeg.server.modules.fas.dto.SurplusLossesDTO;
import com.lty.jeeg.server.modules.fas.vo.SurplusLossesVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lty.jeeg.server.common.page.table.PageTableRequest;
import com.lty.jeeg.server.common.page.table.PageTableResponse;

import com.lty.jeeg.server.modules.fas.model.SurplusLosses;
import com.lty.jeeg.server.modules.fas.service.SurplusLossesService;

import io.swagger.annotations.ApiOperation;

/**
 * @author : xuchen
 * @date : 2019-03-11 09:45:43
 * Description : 盘盈盘亏记录
 */
@Api(tags = "盘盈盘亏记录")
@RestController
@RequestMapping("/surplusLosses")
public class SurplusLossesController {

    private final SurplusLossesService surplusLossesService;

    @Autowired
    public SurplusLossesController(SurplusLossesService surplusLossesService) {
        this.surplusLossesService = surplusLossesService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public ResponseInfo get(@PathVariable Long id) {
        return ResponseUtil.success(BeanConverter.map(surplusLossesService.getById(id), SurplusLossesVO.class));
    }

    @PostMapping
    @ApiOperation(value = "保存")
    public ResponseInfo save(@RequestBody SurplusLossesVO surplusLossesVO) {
        return surplusLossesService.save(BeanConverter.map(surplusLossesVO, SurplusLossesDTO.class),new ResponseInfo());
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public ResponseInfo update(@RequestBody SurplusLossesVO surplusLossesVO) {
        return ResponseUtil.success(surplusLossesService.update(BeanConverter.map(surplusLossesVO, SurplusLossesDTO.class)));
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public ResponseInfo delete(@PathVariable Long id) {
        return ResponseUtil.success(surplusLossesService.delete(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return surplusLossesService.list(request);
    }

}
